using Godot;

public partial class TopDownCamera : Camera3D
{
	[Export] public float MoveSpeed = 5;
	[Export] public float ScaleSpeed = 2;
	[Export] public float lerp = 0.01f;

	private Vector3 targetPosition;

	public override void _Ready()
	{
		SetProcessInput(true);
		targetPosition = GlobalTransform.Origin;
	}

	public override void _Process(double delta)
	{
		float moveDistance = MoveSpeed * (float)delta;
		float height = ScaleSpeed * (float)delta;

		// 计算新的目标位置
		if (Input.IsActionPressed("MoveCameraRight"))
		{
			targetPosition += new Vector3(0, 0, moveDistance);
		}
		if (Input.IsActionPressed("MoveCameraLeft"))
		{
			targetPosition += new Vector3(0, 0, -moveDistance);
		}
		if (Input.IsActionPressed("MoveCameraUp"))
		{
			targetPosition += new Vector3(moveDistance, 0, 0);
		}
		if (Input.IsActionPressed("MoveCameraDown"))
		{
			targetPosition += new Vector3(-moveDistance, 0, 0);
		}
		if (Input.IsActionPressed("MoveCameraNear"))
		{
			targetPosition += new Vector3(0, -height, 0);
		}
		if (Input.IsActionPressed("MoveCameraFar"))
		{
			targetPosition += new Vector3(0, height, 0);
		}

		// 平滑移动到目标位置
		Vector3 current = GlobalTransform.Origin;
		Vector3 move = current.Lerp(targetPosition, lerp) - current;
		GlobalTransform = GlobalTransform.Translated(move);
	}
}
